﻿<Page x:Class="WpfBinding.HierarchicalDataTemplateDemo"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:WpfBinding"
      mc:Ignorable="d" 
      d:DesignHeight="291" d:DesignWidth="649"
	Title="HierarchicalDataTemplateDemo">
    <Page.Resources>
        <XmlDataProvider x:Key="dataProvider" XPath="GameStats">
            <x:XData>
                <GameStats xmlns="">
                    <GameStat Type="Beginner">
                        <HighScore>220</HighScore>
                    </GameStat>
                    <GameStat Type="Seconds">
                        <HighScore>300</HighScore>
                    </GameStat>
                    <GameStat Type="Advanced">
                        <HighScore>400</HighScore>
                    </GameStat>
                </GameStats>
            </x:XData>
        </XmlDataProvider>

        <HierarchicalDataTemplate DataType="GameStats" ItemsSource="{Binding XPath=*}">
            <TextBlock  FontStyle="Italic" Text="All Games Stat"/>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="GameStat" ItemsSource="{Binding XPath=*}">
            <TextBlock    FontWeight="Bold" Text="{Binding XPath=@Type}" />
        </HierarchicalDataTemplate>
        <DataTemplate DataType="HighScore">
            <TextBlock  Foreground="Red" Text="{Binding XPath=.}"/>
        </DataTemplate>
       
    </Page.Resources>
    <Canvas>
        <TreeView x:Name="tr" ItemsSource="{Binding Source={StaticResource dataProvider},XPath=.}"   
                  Width="300" Height="200" Canvas.Top="10" Canvas.Left="10"   />
        <Button Canvas.Left="73" Canvas.Top="225" Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />
        <Menu Canvas.Left="346" Canvas.Top="12" Height="23" Name="menu1" Width="200" 
              ItemsSource="{Binding Source={StaticResource dataProvider},XPath=.}" />
        <TreeView Canvas.Left="354" Canvas.Top="74" Height="200"   Name="dictree" Width="120" ItemsSource="{Binding}" >
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Value}">
                    <TextBlock Text="{Binding Key}"></TextBlock>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock >
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="ID:{0} Name:{1}">
                                        <Binding Path="Id" />
                                        <Binding Path="Name" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
               </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
        <TextBlock Canvas.Left="510" Canvas.Top="162" Height="23" Name="textBlock1" Text="TextBlock" />
    </Canvas>
</Page>
